package cn.bandeqing.index.rpc.impl;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.index.req.ProductRecommendListReq;
import cn.bandeqing.index.resp.ProductTypeResp;
import cn.bandeqing.index.rpc.IIndexRpc;
import cn.bandeqing.product.entity.ProductStatus;
import cn.bandeqing.product.resp.ProductListResp;
import cn.bandeqing.product.service.IProductService;
import cn.bandeqing.productType.service.IProductTypeService;
import cn.bandeqing.sys.resp.DictResp;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.hutool.core.map.MapUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.bandeqing.product.entity.table.ProductTableDef.PRODUCT;
import static cn.bandeqing.productType.entity.table.ProductTypeTableDef.PRODUCT_TYPE;

@DubboService
public class IndexRpcImpl implements IIndexRpc {

    @Resource
    private IProductService productService;
    @Resource
    private IProductTypeService productTypeService;

    @Override
    public Resp<List<ProductListResp>> productHotList() {

        List<ProductListResp> hotProductList = productService.listAs(QueryWrapper.create()
                .where(PRODUCT.PRODUCT_STATUS.eq(ProductStatus.ok))
                .where(PRODUCT.INDEX_HOT.eq(true))
                .limit(6), ProductListResp.class);

        return Resp.success(hotProductList);
    }

    @Override
    public Resp<List<ProductTypeResp>> productTypeList() {

        List<ProductTypeResp> productTypeResps = productTypeService.listAs(QueryWrapper.create()
                .where(PRODUCT_TYPE.INDEX_SWITCH.eq(true))
                .orderBy(PRODUCT_TYPE.PT_SORT.asc()), ProductTypeResp.class);

        return Resp.success(productTypeResps);
    }

    @Override
    public Resp<List<ProductListResp>> productRecommendList(ProductRecommendListReq req) {
        List<ProductListResp> productListResps = productService.listAs(QueryWrapper.create()
                .where(PRODUCT.PRODUCT_TYPE_ID.eq(req.getProductTypeId()))
                .where(PRODUCT.INDEX_RECOMMEND.eq(true))
                .limit(4), ProductListResp.class);

        return Resp.success(productListResps);
    }

}
